home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / turric03.zip / TURRIC03.ZIP / PROGS / FLAMER.QC < prev    next >
Text File  |  1997-02-06  |  7KB  |  318 lines

  1. /*
  2. ==============================================================================
  3.  
  4. FLAMETHROWER
  5.  
  6. ==============================================================================
  7. */
  8. // prototypes
  9. float() crandom;
  10. void(entity burnee) SpawnFlame2;
  11. void() bubble_bob;
  12.  
  13.  
  14. /*
  15. ================
  16. FlameDie
  17. ================
  18. Function for the death of a flame.
  19. */
  20. void () FlameDie =
  21. {
  22.     local    float    rn;
  23.  
  24.     rn = random();
  25.  
  26. // 30% die out, 40% keep going, 30% spread. Flames always die out for zombies.
  27.     if(rn <= 0.3 || self.owner.classname == "zombie")
  28.     {
  29.         self.owner.onfire = self.owner.onfire - 1;
  30.         SUB_RemoveTempEnt();
  31.     }
  32.     else
  33.     {
  34.         self.alivetime = time + 5;
  35.         if(rn > 0.7)
  36.         {
  37.             SpawnFlame2(self.owner);
  38.         }
  39.     }
  40. };
  41.  
  42. /*
  43. ================
  44. Burn
  45. ================
  46. Think function for flames burning on an entity.
  47. */
  48. void () Burn =
  49. {
  50.     local    vector    height_v;
  51.     local    float    height_f;
  52.     local    float    rn;
  53.  
  54. // Set next time to think.
  55.     self.nextthink = time + 0.1;
  56.     self.think = Burn;
  57.  
  58.     if(self.owner.onfire <= 0)
  59.     {
  60.         self.owner.onfire = 0;
  61.         SUB_RemoveTempEnt();
  62.         return;
  63.     }
  64.  
  65. // Check if flame has been extinguished.
  66.     if((self.owner.waterlevel >= 2 || self.waterlevel >= 2) && self.owner.watertype != CONTENT_LAVA)
  67.     {
  68.         sound (self.owner, CHAN_WEAPON, "player/slimbrn2.wav", 1, ATTN_NORM);
  69.         self.owner.effects = self.owner.effects - (self.owner.effects & EF_BRIGHTLIGHT);
  70.         self.owner.onfire = self.owner.onfire - 1;
  71.         SUB_RemoveTempEnt();
  72. // Message to player.
  73.         if(self.owner.classname == "player")
  74.         {
  75.             sprint(self.owner, "You put yourself out\n");
  76.         }
  77.         return;
  78.     }
  79.  
  80.     if(self.burncounter >= 10)
  81.     {
  82. // Make burning sound.
  83.         rn = random();
  84.         if((rn <= 0.5) && (time > self.wait))
  85.         {
  86.             sound (self, CHAN_WEAPON, "weapons/flame.wav", 0.7, ATTN_NORM);
  87.             self.wait = time + 1;
  88.         }
  89. // Cause damage to owning entity.
  90.         T_Damage (self.owner, self, self, FLAME_DAMAGE);
  91.         self.burncounter = 0;
  92. // Warning message to player.
  93.         if(self.owner.classname == "player")
  94.         {
  95.             sprint(self.owner, "You are on fire!\n");
  96.         }
  97.     }
  98.     self.burncounter = self.burncounter + 1;
  99.  
  100. // Check if it's time to die out.
  101.     if(time > self.alivetime)
  102.     {
  103.         FlameDie();
  104.         return;
  105.     }
  106.  
  107. // Check height of flame and reset if too high.
  108.     height_v = self.origin - self.owner.origin;
  109.     height_f = vlen(height_v);
  110.  
  111.     if(height_f >= 40)
  112.     {
  113.         setorigin (self, self.owner.origin + self.base_point);
  114.     }
  115.  
  116.     self.velocity_x = 80 * crandom();
  117.     self.velocity_y = 80 * crandom();
  118.     self.velocity_z = 300 * random();
  119. };
  120.  
  121. /*
  122. ================
  123. Flame2Touch
  124. ================
  125. Touch function for the flames burning on an entity.
  126. */
  127. void () Flame2Touch =
  128. {
  129.     local    float    rn;
  130.  
  131.     if(other == world)
  132.         return;
  133.  
  134.     if((other != self.owner) && (other.onfire < 5))
  135.     {
  136. // The fire spreads 50% of the time.
  137.         rn = random();
  138.         if( rn <= 0.5)
  139.         {
  140.             other.onfire = other.onfire + 1;
  141.             SpawnFlame2(other);
  142.         }
  143.     }
  144. };
  145.  
  146. /*
  147. ================
  148. SpawnFlame2
  149. ================
  150. Spawn a flame that burns on an entity.
  151. */
  152. void(entity burnee) SpawnFlame2 =
  153. {
  154.     local   entity    flame;
  155. // To prevent packet overflows from too many flames being created.
  156.     if (current_temp_entities >= MAX_TEMP_ENTITIES)
  157.     {
  158.         return;
  159.     }
  160.     else
  161.     {
  162.         current_temp_entities = current_temp_entities + 1;
  163.  
  164.         flame = spawn();
  165.         flame.owner = burnee;
  166.         flame.movetype = MOVETYPE_FLYMISSILE;
  167.         flame.solid = SOLID_BBOX;
  168.         flame.classname = "flame2";
  169.         flame.touch = Flame2Touch;
  170.         flame.nextthink = time + 0.1;
  171.         flame.think = Burn;
  172.         setmodel (flame, "progs/flame2.mdl");
  173.         setsize (flame, '0 0 0', '0 0 0');
  174.         flame.alivetime = time + 5;
  175.  
  176. // Base point to burn above.
  177.         flame.base_point = crandom() * '15 0 0' + crandom() * '0 15 0'+ crandom() * '0 0 15';
  178.         setorigin (flame, burnee.origin + flame.base_point);
  179.         flame.velocity_x = 80 * crandom();
  180.         flame.velocity_y = 80 * crandom();
  181.         flame.velocity_z = 300 * random();
  182.         flame.avelocity = '0 0 0';
  183.     }
  184. };
  185.  
  186. /*
  187. ================
  188. Flame1Touch
  189. ================
  190. Touch function for the flames fired from the flame unit.
  191. */
  192. void () Flame1Touch =
  193. {
  194.     local   float   rn;
  195.  
  196.     if (other.takedamage)
  197.     {
  198. // 50% chance of flame catching the touched entity on fire.
  199. // If entity not already at maximum combustion level.
  200.         rn = random();
  201.         if ((rn <= 0.5) && (other.onfire < 5))
  202.         {
  203. // Make the entity more on fire.
  204.             other.onfire = other.onfire + 1;
  205.             other.effects = other.effects + (other.effects & EF_BRIGHTLIGHT);
  206.             SpawnFlame2(other);
  207.         }
  208. // Damage the touched entity.
  209.         T_Damage (other, self, self.owner, FLAME_DAMAGE);
  210. // Remove self.
  211.         SUB_RemoveTempEnt();
  212.     }
  213.     else
  214.     {
  215. // If hit a non damagable entity.
  216.         self.velocity = '0 0 0';
  217.         self.velocity_z = random()*24 + 24;
  218.     }
  219. };
  220.  
  221. /*
  222. ================
  223. FlamerBubbles
  224. ================
  225. Fire a flame from the flame unit.
  226. */
  227. void() FlamerBubble =
  228. {
  229. local     entity    bubble;
  230.  
  231.     if (self.waterlevel != 3)
  232.         return;
  233.  
  234. // To prevent packet overflows from too many flames being created.
  235.     if (current_temp_entities >= MAX_TEMP_ENTITIES)
  236.     {
  237.         return;
  238.     }
  239.     else
  240.     {
  241.         current_temp_entities = current_temp_entities + 1;
  242.         current_flame_bubbles = current_flame_bubbles + 1;
  243.         bubble = spawn();
  244.         setmodel (bubble, "progs/s_bubble.spr");
  245.         setorigin (bubble, self.origin + v_forward * 40);
  246.         bubble.movetype = MOVETYPE_NOCLIP;
  247.         bubble.solid = SOLID_NOT;
  248.         bubble.velocity = '0 0 15';
  249.         bubble.classname = "flamer_bubble";
  250.         bubble.nextthink = time + 0.5;
  251.         bubble.think = bubble_bob;
  252.         bubble.frame = 0;
  253.         bubble.cnt = 0;
  254.         setsize (bubble, '-8 -8 -8', '8 8 8');
  255.     }
  256. };
  257.  
  258. /*
  259. ================
  260. W_FireFlame
  261. ================
  262. Fire a flame from the flame unit.
  263. */
  264. void() W_FireFlame =
  265. {
  266.     local   entity    flame;
  267.     local   float     rn;
  268.  
  269. // To prevent packet overflows from too many flames being created.
  270.     if (current_temp_entities >= MAX_TEMP_ENTITIES)
  271.     {
  272.         sprint(self, "fuel blockage in flame unit\n");
  273.         return;
  274.     }
  275.  
  276. // Rocket fuel usage
  277.     self.rocket_fuel = self.rocket_fuel - 1;
  278.     if (self.rocket_fuel <= 0)
  279.     {
  280.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  281.         self.rocket_fuel = 3;
  282.     }
  283.  
  284. // If attempt to fire the flame unit under water.
  285.     if (self.waterlevel > 2)
  286.     {
  287.         FlamerBubble();
  288.  
  289.         rn = random();
  290.         if (rn < 0.5)
  291.             sound (self, CHAN_WEAPON, "misc/water1.wav", 1, ATTN_NORM);
  292.         else
  293.             sound (self, CHAN_WEAPON, "misc/water2.wav", 1, ATTN_NORM);
  294.         return;
  295.     }
  296.  
  297. // Fire a flame of type flame1.
  298.     sound (self, CHAN_WEAPON, "hknight/hit.wav", 1, ATTN_NORM);
  299.  
  300.     flame = spawn();
  301.     flame.owner = self;
  302.     flame.movetype = MOVETYPE_FLYMISSILE;
  303.     flame.solid = SOLID_BBOX;
  304.     flame.classname = "flame1";
  305.     setmodel (flame, "progs/flame2.mdl");
  306.     setsize (flame, '0 0 0', '0 0 0');
  307.     setorigin (flame, self.origin + v_forward * 32 + v_up * (random()*16 - 8) + '0 0 16');
  308.     flame.effects = EF_DIMLIGHT;
  309.     flame.touch = Flame1Touch;
  310.     flame.think = SUB_RemoveTempEnt;
  311.     flame.nextthink = time + 1.5;
  312.  
  313. // set flame speed
  314.  
  315.     makevectors (self.v_angle);
  316.     flame.velocity = (aim(self, 10000)* 400)+'0 0 32' + v_right * (random()*16 - 8);
  317. };
  318.